home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ansi / help_7n1.zip / HELP.ASM < prev    next >
Assembly Source File  |  1987-10-02  |  22KB  |  816 lines

  1. ;from VOL7N1.ARC, PC Magazine Jan 88?
  2. ;            Help.asm
  3. ;         Resident help facility
  4. ; Format:  HELP filespec [... filespec][/Nn][/P][/Hn] | [/U]
  5. ; defaults: pages = 4; hot key = Alt H
  6.  
  7. CODE SEGMENT                ;********************************;
  8. ASSUME CS:CODE,DS:CODE            ;*                *;
  9. ORG 100H                ;*  Requires MASM 2.0 or later  *;
  10.                     ;*    Remember to EXE2BIN    *;
  11. START:        JMP    BEGINNING    ;*                *;
  12.                     ;********************************;
  13.  
  14. ;        DATA AREA
  15. ;        ---------
  16. COPYRIGHT    DB    "HELP 1.0 (c) 1987 Ziff Communications Co.",13,10
  17.         DB    "Successfully installed",13,10
  18. ALT_COMBO    DB    "Press Alt H to activate",10,0,26
  19.  
  20. PROGRAMMER    DB    "Michael J. Mefford"
  21.  
  22. OLD_KEYBOARD    DD    ?
  23. CRT_COLS    DW    ?
  24. STATUS_REG    DW    ?
  25. SCREEN_SEG    DW    0B000H
  26. LINE_COUNT    DB    25
  27. IMMEDIATE_FLAG    DB    0
  28. BUSY        DB    0
  29.  
  30. IMMEDIATE    DW    POP_IT
  31. DATA_SEG    DW    ?
  32. DATA_INT    DB    0
  33. INSTALLED_FLAG    DB    0
  34. POPUP_FLAG    DB    0
  35. HOT_KEY        DB    35
  36.  
  37. FILENAME    DW    ?
  38. ERROR_LEVEL    DB    0
  39.  
  40. CURRENT_PAGE    DB    1
  41. RESERVED_PAGES    DB    4
  42. ACTIVE_PAGES    DB    0
  43. PAGE_COUNT    DB    0
  44. DELIMITERS    DB    9,32,13,44,";","/"
  45.  
  46. SYNTAX LABEL BYTE
  47. DB  10,"Usage:  HELP filespec [... filespec][/Nn][/Hn][/P] | [/U]",13,10,10
  48. DB    "/Nn where n = number of reserved pages (1-14); default = 4",13,10
  49. DB    "/Hn where n = Alt hot key combo (A-Z,0-9,",34,45,34,44,34,61,34
  50. DB    "); default = H",13,10
  51. DB    "/P  = immediate pop-up",13,10
  52. DB    "/U  = uninstall",13,10,10
  53. DB    "Use: PgUp PgDn Home End to navigate through HELP",13,10
  54. DB    5 DUP(32),"ESC or hot key to exit",10,0
  55.  
  56.  
  57. ACTIVE_MSG    DB    " active page(s)",13,10,0
  58. RESERVED_MSG    DB    " total page(s)",13,10,10,0
  59. UNLOAD_MSG    DB    10,"HELP can't be uninstalled.",13,10
  60.         DB    "Uninstall resident programs in reverse order.",10,0
  61. UNINSTALL_MSG    DB    10,"HELP uninstalled",10,0
  62. NO_FREE        DB    "Too many resident programs",0
  63. NOT_FOUND    DB    32,"not found",13,10,0
  64. NOT_ENOUGH    DB    "Not enough memory",0
  65. ALLOCATE_MSG    DB    "Memory allocation error",13,10,0
  66.  
  67. SCAN_CODES LABEL BYTE
  68.  
  69. DB 45,130,48,129,49,120,50,121,51,122,52,123,53,124
  70. DB 54,125,55,126,56,127,57,128,61,131,65,30,66,48,67
  71. DB 46,68,32,69,18,70,33,71,34,72,35,73,23,74,36,75,37
  72. DB 76,38,77,50,78,49,79,24,80,25,81,16,82,19,83,31
  73. DB 84,20,85,22,86,47,87,17,88,45,89,21,90,44
  74.  
  75. ;                SCAN CODES FOR ALT COMBO
  76. ;
  77. ;    Code Key    Code Key    Code Key    Code    Key
  78. ;    16   Q        30   A        44    Z    120    1
  79. ;    17   W        31   S        45    X    121    2
  80. ;    18   E        32   D        46    C    122    3
  81. ;    19   R        33   F        47    V    123    4
  82. ;    20   T        34   G        48    B    124    5
  83. ;    21   Y        35   H        49    N    125    6
  84. ;    22   U        36   J        50    M    126    7
  85. ;    23   I        37   K                127    8
  86. ;    24   O        38   L                128    9
  87. ;    25   P                        129    0
  88. ;                            130    -
  89. ;    Default is 35 (Alt H)                131    =
  90.  
  91.  
  92. ;************* KEYBOARD INTERCEPTOR *************;
  93.  
  94. NEW_KEYBOARD:
  95.     STI
  96.     PUSHF                ;Simulate an interrupt
  97.     CALL    CS:OLD_KEYBOARD        ; by pushing flags and far call.
  98.  
  99. POP_IT:    PUSHF                ;On return save all registers
  100.     PUSH    DS            ; that will be used.
  101.     PUSH    ES
  102.     PUSH    AX
  103.     PUSH    BX
  104.     PUSH    CX
  105.     PUSH    DX
  106.     PUSH    SI
  107.     PUSH    DI
  108.     PUSH    BP
  109.  
  110.     PUSH    CS            ;Point to our data.
  111.     POP    DS
  112.     CLD                ;Moves in forward direction.
  113.     MOV    AX,40H            ;Point to ROM BIOS data area
  114.     MOV    ES,AX
  115.     MOV    AX,ES:[4AH]        ;Get number of columns on screen
  116.     MOV    CRT_COLS,AX        ; and store.
  117.     MOV    AX,ES:[63H]        ;Get base address of video card.
  118.     ADD    AX,6            ;Convert to status register
  119.     MOV    STATUS_REG,AX        ; and store.
  120.     CMP    AX,3BAH            ;Is it mono card?
  121.     JZ    MONO            ;If yes, use b800h.
  122.     MOV    SCREEN_SEG,0B800H        ; else point to color card.
  123. MONO:    MOV    AL,ES:[49H]        ;Retrieve video mode.
  124.     CMP    AL,3            ;Is it text mode?
  125.     JBE    GOOD_MODE            ;If yes, OK.
  126.     CMP    AL,7
  127.     JNZ    DONE_HERE            ;Exit if graphics
  128.  
  129. GOOD_MODE:
  130.     CMP    IMMEDIATE_FLAG,1         ;Is there a pop-up request?
  131.     JZ    NOW            ;If yes, pop-up right now.
  132.     CMP    BUSY,1            ;If the window is already popped
  133.     JZ    DONE_HERE            ; exit Int 9 back to window.
  134.     MOV    AH,1            ;Is an ASCII character ready?
  135.     INT    16H
  136.     JZ    DONE_HERE            ;If it's just a key release, exit.
  137.     CMP    AL,0            ;Is it extended code?
  138.     JNZ    DONE_HERE            ;If no, exit.
  139.     CMP    AH,HOT_KEY        ;Else, see if our Alt key combo.
  140.     JZ    OPEN_WINDOW        ;If yes, open window
  141. DONE_HERE:
  142.     JMP    SHORT EXIT_KEYBOARD    ; else exit.
  143.  
  144. ;------------------------------------;
  145. ; Save screen so we can pop up HELP. ;
  146. ;------------------------------------;
  147.  
  148. OPEN_WINDOW:
  149.     MOV    AH,0            ;Retrieve and discard hot key
  150.     INT    16H            ; character from keyboard buffer.
  151. NOW:    MOV    BUSY,1            ;Flag that window is open.
  152.     MOV    IMMEDIATE_FLAG,0         ;Restore immediate flag.
  153.     CALL    STORE_SCREEN        ;Store screen.
  154.  
  155. ;-----------------------------------------;
  156. ; Loop here looking for valid keystrokes. ;
  157. ;-----------------------------------------;
  158.  
  159. READ_KEY:
  160.     MOV    CL,CURRENT_PAGE        ;Get current page.
  161.     DEC    CL            ;Adjust for starting offset.
  162.     CALL    PAGE_SIZE            ;Get offset.
  163.     MOV    SI,DX
  164.     CALL    WRITE_SCREEN        ;Update the screen.
  165.     MOV    AH,0            ;Wait for a character.
  166.     INT    16H
  167.     CMP    AH,1            ;Is it Esc?
  168.     JZ    EXIT_WINDOW        ;If yes, exit window.
  169.     CMP    AH,BYTE PTR HOT_KEY    ;Is it our key combo?
  170.     JZ    EXIT_WINDOW        ;If yes, exit window.
  171.  
  172.     MOV    CL,CURRENT_PAGE        ;Get current page.
  173.     CMP    AH,49H            ;Is it PgUp?
  174.     JNZ    CK_PGDN
  175.     CMP    CL,1            ;If yes, is it already page one?
  176.     JZ    END_KEY
  177.     DEC    CL            ;If no, decrement page.
  178.  
  179. CK_PGDN:
  180.     CMP    AH,51H            ;Is it PgDn?
  181.     JNZ    CK_HOME
  182.     CMP    CL,ACTIVE_PAGES        ;If yes, are we already last page?
  183.     JZ    END_KEY
  184.     INC    CL            ;If no, increment page.
  185.  
  186. CK_HOME:
  187.     CMP    AH,47H            ;Is it Home?
  188.     JNZ    CK_END
  189.     MOV    CL,1            ;If yes, move to page one.
  190.  
  191. CK_END:    CMP    AH,4FH            ;Is it End?
  192.     JNZ    END_KEY
  193.     MOV    CL,ACTIVE_PAGES        ;If yes, move to last page.
  194.  
  195. END_KEY:
  196.     MOV    CURRENT_PAGE,CL        ;Store new current page.
  197.     JMP    SHORT READ_KEY
  198.  
  199. ;----------------------------------;
  200. ; This is the window exit routine. ;
  201. ;----------------------------------;
  202.  
  203. EXIT_WINDOW:
  204.     MOV    SI,OFFSET SCREEN_BUFFER    ;Point to the stored screen
  205.     CALL    WRITE_SCREEN        ; and restore the screen.
  206.     MOV    IMMEDIATE_FLAG,0         ;Reset the pop-up flag.
  207.     MOV    BUSY,0            ;Flag done with window.
  208.  
  209. EXIT_KEYBOARD:
  210.     POP    BP            ;Restore all registers.
  211.     POP    DI
  212.     POP    SI
  213.     POP    DX
  214.     POP    CX
  215.     POP    BX
  216.     POP    AX
  217.     POP    ES
  218.     POP    DS
  219.     POPF
  220.     IRET                ;Return from interrupt.
  221.  
  222.  
  223. ;************* FILE LOADING AND INSTALL PROCEDURE *************;
  224.  
  225. BEGINNING:
  226.     CLD
  227.     PUSH    CS
  228.     POP    DATA_SEG            ;Store our segment.
  229.     CMP    SP,65533            ;Do we have 64K?
  230.     JA    CK_PARA
  231.     MOV    SI,OFFSET NOT_ENOUGH    ;If no, exit with message.
  232.     JMP    ERROR_EXIT
  233.  
  234. CK_PARA:
  235.     CMP    BYTE PTR DS:[80H],0    ;Any parameters?
  236.     JNZ    CK_FREE
  237. OPTIONS:
  238.     MOV    SI,OFFSET SYNTAX         ;If no, exit with syntax message.
  239.     JMP    ERROR_EXIT
  240.  
  241. ;----------------------------------------------------------------------;
  242. ; Check user vectors to see if we are installed or if one is available ;
  243. ;----------------------------------------------------------------------;
  244.  
  245. CK_FREE:
  246.     MOV    AL,60H - 1        ;Available vectors are 60H - 67H.
  247. FREE_USER_INT:
  248.     INC    AL
  249.     MOV    AH,35H            ;Get vector address.
  250.     INT    21H
  251.     CMP    BX,0            ;Is offset being used?
  252.     JNZ    CK_SIGNATURE        ;If yes, see if it's us.
  253.     MOV    DX,ES
  254.     or    dx,dx    ;CMP    DX,0    ;Is segment being used?
  255.     JNZ    CK_SIGNATURE        ;If yes, see if it's us.
  256.     MOV    DATA_INT,AL        ;If available, save INT number.
  257.  
  258. NEXT_USER:
  259.     CMP    AL,67H            ;Have we checked all 7?
  260.     JNZ    FREE_USER_INT        ;If no, next one.
  261.     JMP    SHORT CK_SWITCHES
  262.  
  263. CK_SIGNATURE:
  264.     MOV    DI,BX            ;See if INT has our signature.
  265.     MOV    SI,100H
  266.     MOV    CX,30/2
  267.     REPZ    CMPSW
  268.     JNZ    NEXT_USER        ;If yes, already installed.
  269.     MOV    DATA_SEG,ES        ;Save segment.
  270.     MOV    INSTALLED_FLAG,1
  271.  
  272. ;--------------------------------------------;
  273. ; Check the command line for switch options. ;
  274. ;--------------------------------------------;
  275.  
  276. CK_SWITCHES:
  277.     PUSH    DATA_SEG        ;First point to installed segment.
  278.     POP    ES
  279.     MOV    SI,81H            ;First parameter.
  280.  
  281. NEXT_SWITCH:
  282.     LODSB                ;Get a byte.
  283.     CMP    AL,13            ;Is it carriage return?
  284.     JZ    CK_FILENAMES        ;If yes, done here.
  285.     CMP    AL,"/"            ;Is it switch character?
  286.     JNZ    NEXT_SWITCH        ;If no, get next byte
  287.     LODSB                ; else get switch.
  288.     CMP    AL,13            ;Is it carriage return?
  289.     JZ    CK_FILENAMES        ;If yes, done here
  290.     CALL    CAPITALIZE        ; else capitalize.
  291.  
  292.     CMP    AL,"U"            ;Is it "U"?
  293.     JNZ    CK_N
  294.     CMP    INSTALLED_FLAG,1     ;If yes, are we installed?
  295.     JNZ    NEXT_SWITCH
  296.     JMP    UNINSTALL            ;If yes, uninstall.
  297.  
  298. CK_N:    
  299.     CMP    AL,"N"            ;Is it "N"?
  300.     JNZ    CK_P
  301.     CMP    INSTALLED_FLAG,1     ;If yes, are we installed?
  302.     JZ    NE